package com.rao.gmall.web.all.controller;

import com.rao.gmall.common.util.AuthContextHolder;
import com.rao.gmall.web.all.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @author nzmxfan
 * @create 2021-08-20-19:22
 */
@Controller
public class OrderController {

    @Autowired
    OrderService orderService;

    @GetMapping("/trade.html")
    public String getOrderHtml(Model model, HttpServletRequest request){
        // 使用工具类获取 userId
        String userId = AuthContextHolder.getUserId(request);

        // 获取订单相关的属性： userAddressList、detailArrayList、totalNum、totalAmount
        Map<String, Object> map = orderService.getOrderInfo(userId);
        model.addAllAttributes(map);

        return "order/trade";
    }

    /**
     * 跳转到订单列表页
     * @return
     */
    @GetMapping("/myOrder.html")
    public String orderListPage(){
        //页面不需要任何数据
        return "order/myOrder";
    }
}
